package com.easylinkin.linkappapi.investigation.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.investigation.entity.InvestigationTask;
import com.easylinkin.linkappapi.investigation.service.InvestigationTaskService;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 排查任务 前端控制器
 * </p>
 *
 * @author TongJie
 * @since 2021-04-16
 */
@RestController
@RequestMapping("/investigation/investigationTask")
public class InvestigationTaskController {

    @Resource
    private InvestigationTaskService service;

    /**
     * 查询分页
     */
    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<InvestigationTask> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<InvestigationTask> record = service.getPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    /**
     * 查询详情（处理）
     */
    @PostMapping("getInvestigationTaskWithDetails")
    public RestMessage getInvestigationTaskWithDetails(@RequestBody InvestigationTask requestModel) {
        Assert.notNull(requestModel.getId(), "id 不能为空");
        return RestBuilders.successBuilder().data(service.getInvestigationTaskWithDetails(requestModel)).build();
    }
    /**
     * 查询详情（查看）
     */
    @PostMapping("getInvestigationTaskWithDetailsAll")
    public RestMessage getInvestigationTaskWithDetailsAll(@RequestBody InvestigationTask requestModel) {
        Assert.notNull(requestModel.getId(), "id 不能为空");
        return RestBuilders.successBuilder().data(service.getInvestigationTaskWithDetailsAll(requestModel)).build();
    }


//    @PostMapping("test_generateTask")
//    public RestMessage test_generateTask() {
//        service.generateTask();
//        return RestBuilders.successBuilder().data(null).build();
//    }

    /**
     * 生成临时任务
     *
     * 通过任务模板生成 任务实例
     */
    @PostMapping("addTaskByTaskModel")
    public RestMessage addTaskByTaskModel(@RequestBody InvestigationTask requestModel) {
        Assert.notNull(requestModel, "参数为空");
        Assert.notNull(requestModel.getInvestigationTaskModelId(), "investigationTaskModelId 参数为空");
        service.addTaskByTaskModel(requestModel);
        return RestBuilders.successBuilder().build();
    }
    
    /**
     * 生成临时任务
     *
     * 通过任务模板生成 任务实例
     */
    @PostMapping("batchDelete")
    public RestMessage addTaskByTaskModel(@RequestBody List<Long> ids) {
        service.batchDelete(ids);
        return RestBuilders.successBuilder().build();
    }

    /**
     * 处理任务
     */
    @PostMapping("handle")
    public RestMessage handle(@RequestBody InvestigationTask requestModel) {
        service.handle(requestModel);
        return RestBuilders.successBuilder().build();
    }

}
